{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 2. 创建第一个视觉程序“Hello，world！”，显示Lena图片。具体效果参看课程PPT。 "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import cv2 as cv\n",
    "img = cv.imread('./lena.jpg')\n",
    "cv.imshow('Hello World!', img)\n",
    "cv.waitKey()\n",
    "cv.destroyAllWindows()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 3. 对Lena图像，分解得到RGB分量及HSV分量，显示各分量，并对结果进行比较说明。\n",
    "对Lena图像进行BGR分解后，可以看到整体上R分量较大，G较小，B适中，说明该图像颜色偏向红光和蓝光的混合光，即整体画面偏紫红。\n",
    "\n",
    "对Lena图像进行HSV分解后，可以看到V分量上拱门和发饰值较小，其余部分值较大，代表该图像采光较好，人像和周围环境具有较高的亮度。\n",
    "S分量是饱和度，代表颜色与白光的稀释比例，图中眼白由于几乎没有颜色，所以饱和度低，在S通道显示为接近黑色，而在V通道较黑的拱门和发饰，\n",
    "此时由于只有很少的白光与之稀释，因而具有较高的饱和度，在S通道显示接近白色。H分量代表色度，红色为0，H通道可见为黑色，\n",
    "橙色值稍高于红色，即深灰色，值最大的是紫色，在H通道会显示为白色。由于Lena图色彩较少，且较偏向红色紫色，所以H通道看起来像二值化的黑白图。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "cv.imshow('Blue', img[:, :, 0])\n",
    "cv.imshow('Green', img[:, :, 1])\n",
    "cv.imshow('Red', img[:, :, 2])\n",
    "cv.waitKey()\n",
    "cv.destroyAllWindows()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "hsv = cv.cvtColor(img, cv.COLOR_BGR2HSV)\n",
    "cv.imshow('source image', img)\n",
    "cv.imshow('Hue', hsv[:, :, 0])\n",
    "cv.imshow('Satuaration', hsv[:, :, 1])\n",
    "cv.imshow('Value', hsv[:, :, 2])\n",
    "cv.waitKey()\n",
    "cv.destroyAllWindows()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
